package net.maku.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.system.convert.SysUserWalletConvert;
import net.maku.system.entity.SysUserWalletEntity;
import net.maku.system.service.SysUserWalletService;
import net.maku.system.query.SysUserWalletQuery;
import net.maku.system.vo.SysUserWalletVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 购买订单管理
*
* @author 小陈 www.hong.ch@qq.com
* @since 1.0.0 2025-03-24
*/
@RestController
@RequestMapping("system/wallet")
@Tag(name="购买订单管理")
@AllArgsConstructor
public class SysUserWalletController {
    private final SysUserWalletService sysUserWalletService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('system:wallet:page')")
    public Result<PageResult<SysUserWalletVO>> page(@ParameterObject @Valid SysUserWalletQuery query){
        PageResult<SysUserWalletVO> page = sysUserWalletService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('system:wallet:info')")
    public Result<SysUserWalletVO> get(@PathVariable("id") Long id){
        SysUserWalletEntity entity = sysUserWalletService.getById(id);

        return Result.ok(SysUserWalletConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('system:wallet:save')")
    public Result<String> save(@RequestBody SysUserWalletVO vo){
        sysUserWalletService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('system:wallet:update')")
    public Result<String> update(@RequestBody @Valid SysUserWalletVO vo){
        sysUserWalletService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('system:wallet:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sysUserWalletService.delete(idList);

        return Result.ok();
    }
}